import { AdmModules, WebModules } from '@/modules/modules';
import { INestApplication } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

/**
 * @description 创建并设置 Swagger 文档。
 * @param {INestApplication} app NestJS 应用实例。
 * @returns {void} void。
 */
export function Others_Swaggers_Base(app: INestApplication<any>): void {
  const configService = app.get(ConfigService);
  const swaggers = [
    {
      SWAGGER_TITLE: configService.get<string>('SWAGGER_TITLE'),
      SWAGGER_DESCRIPTION: configService.get<string>('SWAGGER_DESCRIPTION'),
      SWAGGER_URL: configService.get<string>('SWAGGER_URL'),
      includes: AdmModules,
    },
    {
      SWAGGER_TITLE: configService.get<string>('SWAGGER_TITLE_TWO'),
      SWAGGER_DESCRIPTION: configService.get<string>('SWAGGER_DESCRIPTION_TWO'),
      SWAGGER_URL: configService.get<string>('SWAGGER_URL_TWO'),
      includes: WebModules,
    },
  ];
  swaggers.map((item) => {
    const config = new DocumentBuilder()
      .setTitle(item.SWAGGER_TITLE)
      .setDescription(item.SWAGGER_DESCRIPTION)
      .setVersion('1.0')
      .addBearerAuth()
      .build();
    const documentTwo = SwaggerModule.createDocument(app, config, {
      include: item.includes,
    });
    const swaggerOptions = {
      swaggerOptions: {
        docExpansion: 'none',
        persistAuthorization: true,
        defaultModelsExpandDepth: 1,
        defaultModelExpandDepth: 2,
      },
    };
    SwaggerModule.setup(item.SWAGGER_URL, app, documentTwo, swaggerOptions);
  });
}
